
#include "stdafx.h"
#include "SLColor.h"
#include "SLHead.h"

CSLColorContainer* CSLColorContainer::m_pInstance = 0;

CSLColorContainer* CSLColorContainer::GetInstance()
{
	if(m_pInstance == 0)
	{
		m_pInstance = new CSLColorContainer;
	}

	return m_pInstance;
}

CSLColorContainer::CSLColorContainer()
{
	LoadSLColors();
}

CSLColorContainer::~CSLColorContainer()
{
	if(m_pInstance != 0)
	{
		StoreSLColors();
		
		delete m_pInstance;
		m_pInstance = 0;
	}
}

void CSLColorContainer::LoadSLColors()
{
	m_clrBK = SL_BLACK;
	m_clrTitle = SL_BLUE;
	m_clrDefault = SL_BLUE;
	m_clrRise = SL_RED;
	m_clrFall = SL_GREEN;
	m_clrUpdate = SL_FLATBLUE;
}

void CSLColorContainer::StoreSLColors()
{

}

COLORREF CSLColorContainer::GetBKColor()
{
	return m_clrBK;
}

void CSLColorContainer::SetBKColor(COLORREF clrBK)
{
	m_clrBK = clrBK;
}

COLORREF CSLColorContainer::GetTitleColor()
{
	return m_clrTitle;
}

void CSLColorContainer::SetTitleColor(COLORREF clrTitle)
{
	m_clrTitle = clrTitle;
}

COLORREF CSLColorContainer::GetUpdateColor()
{
	return m_clrUpdate;
}

COLORREF CSLColorContainer::GetVarriableColor(int nHeadID, CStock &info)
{
	COLORREF clrResult = m_clrDefault;
	
	switch (nHeadID)
	{
	case SLH_LASTCLOSE:
		clrResult = SL_GREYISH;
		break; 
	case SLH_OPEN:
		if( info.m_fOpen > info.m_fLast )
			clrResult =	m_clrRise;
		else if( info.m_fOpen < info.m_fLast )
			clrResult =	m_clrFall;
		else
			clrResult = SL_GREYISH;
		break;
	case SLH_HIGH:
		if( info.m_fHigh > info.m_fLast )
			clrResult =	m_clrRise;
		else if( info.m_fHigh < info.m_fLast )
			clrResult = m_clrFall;
		else
			clrResult = SL_GREYISH;
		break;
	case SLH_LOW:
		if( info.m_fLow > info.m_fLast )
			clrResult =	m_clrRise;
		else if( info.m_fLow < info.m_fLast )
			clrResult =	m_clrFall;
		else
			clrResult = SL_GREYISH;
		break;
	default:
		clrResult = m_clrDefault;
	}
	
	return clrResult;
}
